Repository navigation
feat(fwss): pay one-time fees as they arise on FilecoinPayV2 - #677
Open
CodeWarriorr wants to merge 20 commits into
Open
CodeWarriorr wants to merge 20 commits into
CodeWarriorr wants to merge 20 commits into
Conversation
Each integration step can move its call sites to v2 without touching the facet constructors again, and the build stays green while v1 is still in use.
forge lint fails on a fresh build once FWSS compiles filecoin-pay-v2: RailId.sol shadows exists() with a return variable of the same name.
New data sets go to FilecoinPayV2 only, while existing ones keep their FilecoinPayV1 rails until they drain. dataSetCreated now opens the rails and locks the lifecycle reserve and CDN lockups in one executeScript call scoped to CREATE_RAIL, and checks the old funding threshold against the payer's v2 balance. The v1 allowance checks have no v2 counterpart, so they and their errors go. Each rail role gets its own nonce, so the cache-miss and CDN rails stay apart when the payee is the FilBeam beneficiary. The PDP rail carries FLAG_CALLBACK for the IRailV2 settlement that follows. _createRails is virtual so tests can keep creating v1 data sets through a test-only module and still cover the flows after creation on them.
Synapse and other clients can't all move to FilecoinPayV2 at the FWSS upgrade, so creation keeps FilecoinPayV1 by default and existing clients see no change. A client opts a new data set into FilecoinPayV2 with the withPayV2 metadata key, which the payer signs with the rest of the metadata, the same way withCDN turns on the CDN rails. This brings back the FilecoinPayV1 creation path and its four errors, and drops the test-only module that recreated it.
The opt-in paragraph read as if the rest of the spec applied to FilecoinPayV2 rails too. Also note that its CREATE_RAIL grant has no allowance caps.
The team settled on packing the payment version into storage terms instead of a signed metadata key, which costs a stored metadata entry on every v2 data set. StorageTerms gains a uint8 payVersion (0 is FilecoinPayV1, 1 is FilecoinPayV2) in a free byte of the record's first slot, so record zero and existing records stay on v1. Terms with a nonzero version hash under their own type, so v1 ids do not move and the same prices on each version get their own id.
The v2 path read the payer's balance and checked the v1 funding threshold, including fee headroom, before running the script. FilecoinPayV2 already reverts the script when a lock does not fit, so the extra call and the headroom check go, as asked in review.
…ated # Conflicts: # service_contracts/src/lib/FWSSFilecoinPayV2.sol
No terms besides record zero are registered on Mainnet or Calibnet, so a single formula costs no released id and drops the v1 branch.
FilecoinPayV2 refills address the PDP rail by its nonce, so the nonce moves next to the other FilecoinPayV2 helpers. The refill threshold becomes a pure function both payment versions can use.
On a FilecoinPayV2 data set the lifecycle reserve is a lock on the PDP rail, so the refill locks the shortfall there. It adds rather than sets, because the rail's available balance also holds payment the settlement callback keeps for open proving periods.
wjmelements
reviewed
Nov 26, 2026
| // The PDP rail's available balance also holds settled payment, so add the shortfall, never set it. | ||
| address token = LibStorageTerms.getRecord(info.storageTermsId).token; | ||
| _lockOnPdpRail(dataSetId, token, payer, info.payee, replenished - reserveBalance); | ||
| info.lifecycleReserveBalance = replenished; |
Contributor
There was a problem hiding this comment.
instead of doing this, the "lifecycle reserve" only needs to contain the termination fee. All other fees can be assessed as we go. Then don't need to maintain lifecycleReserveBalance (or replenish) because the fixed lockup will always be the scaled TERMINATE_FEE.
Collaborator
Author
LibRails is typed on FilecoinPayV1, so the v2 rail code gets its own library, called the same way as LibRails.createRails.
…' into feat/fwss-pay-v2-pieces-scheduled-remove # Conflicts: # service_contracts/src/modules/FWSSDataSetModule.sol
Base automatically changed from
feat/fwss-pay-v2-dataset-created
to
feat/filecoin-pay-v2
November 26, 2026 11:05
…fwss-pay-v2-pieces-scheduled-remove
createRails now derives the PDP nonce through pdpRailNonce, so one place computes it. FWSSFilecoinPayV2 keeps only the FilecoinPayV2 address and _isV1Rail.
FilecoinPayV2 lets FWSS lock and disburse from the payer's balance without a grant, so v2 data sets no longer need a lifecycle reserve to fund one-time fees. The PDP rail keeps only the scaled terminate fee locked. Creation pays its fee in the rail script, and scheduling piece removals pays its fee with a lock and a disburse on the PDP rail. Nothing waits in pendingOneTimePayments, so the v2 refill path and LibRails.replenishedReserve go away.
This was referenced Nov 27, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
FilecoinPayV2 lets FWSS lock and disburse from the payer's balance without a grant, so v2 data sets don't need a lifecycle reserve to fund one-time fees. The PDP rail keeps only the terminate fee locked, and every other fee goes to the payee when it arises.
Part of #669
What's changed
CREATE_RAILscript, instead of locking $0.50piecesScheduledRemoveon v2 pays its fee withlock+disburseon the PDP rail (LibRailsV2.chargeOnPdpRail), with no refilllifecycleReserveBalanceand keeppendingOneTimePaymentsat zero, so held payment insettleRail(Add settleRail #673) is stillavailableminus the reserveLibRailsV2.pdpRailNonce, shared bycreateRailsand the fee chargeNo ABI or storage change.